<?php
/**
 * 系统配置基类
 * User: Administrator
 * Date: 2018\9\19 0019
 * Time: 16:14
 */

namespace app\Lib\Model\SysConfig\SysConfigManage;


use app\Lib\Model\DbModel\AdminConfig;
use app\validate\AdminConfigValidate;

abstract class ConfigCommon implements \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
{
    protected $variable;
    protected $keysVal;
    protected $remark;
    protected $title;
    protected $group;
    protected $type;
    protected $configType;
    protected $sort = 0;
    protected $table;
    protected $validate;
    /**
     * 设置配置键
     * @param $variable
     * @return \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
     */
    public function setVariable($variable)
    {
        $this->variable = $variable;
        return $this;
    }

    /**
     * 设置配置值
     * @param $keysVal
     * @return \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
     */
    public function setKeysVal($keysVal)
    {
        $this->keysVal = $keysVal;
        return $this;
    }

    /**
     * 设置备注
     * @param $remark
     * @return \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
     */
    public function setRemark($remark)
    {
        $this->remark = $remark;
        return $this;
    }

    /**
     * 设置标题
     * @param $title
     * @return \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
     */
    public function setTitle($title)
    {
        $this->title = $title;
        return $this;
    }

    /**
     * 设置分组
     * @param $group
     * @return \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
     */
    public function setGroup($group)
    {
        $this->group = $group;
        return $this;
    }

    /**
     * 设置类型
     * @param $type
     * @return \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
     */
    public function setType($type)
    {
        $this->type = $type;
        return $this;
    }

    /**
     * 设置配置项
     * @param $configType
     * @return \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
     */
    public function setConfigType($configType)
    {
        $this->configType = $configType;
        return $this;
    }

    /**
     * 设置排序
     * @param $sort
     * @return \app\Lib\InterfaceIn\SysConfig\SysConfigManage\ConfigCommon
     */
    public function setSort($sort)
    {
        $this->sort = $sort;
        return $this;
    }

    protected function handleArray(){
        $model = $this->getTable();
        $data = [
            $model->_type =>$this->type,
            $model->_remark=>$this->remark,
            $model->_title=>$this->title,
            $model->_config_type=>$this->configType,
            $model->_group=>$this->group,
            $model->_keys_val=>$this->keysVal,
            $model->_sort=>$this->sort,
            $model->_variable=>$this->variable,
        ];
        return $data;
    }
    protected function getTable(){
        if(empty($this->table)){
            $this->table = new AdminConfig();
        }
        return $this->table;
    }
    protected function getValidate(){
        if(empty($this->validate)){
            $this->validate = new AdminConfigValidate();
        }
        return $this->validate;
    }
}